<template>
	<view class="schedule-list">
		<template v-if="scheduleList.length > 0">
			<view 
				v-for="(schedule, index) in scheduleList" 
				:key="index"
				class="schedule-item"
			>
				<view class="user-avatar">
					<text class="avatar-text">头像</text>
				</view>
				<view class="schedule-content">
					<view class="schedule-title">{{ schedule.title }}</view>
					<view class="schedule-time">{{ schedule.time }}</view>
					<view class="schedule-tag">
						<view class="tag-dot" :style="{ backgroundColor: schedule.tagColor }"></view>
						<text class="tag-name">{{ schedule.tagName }}</text>
					</view>
				</view>
				<view class="schedule-actions" v-if="schedule.showActions">
					<view class="action-edit" @click="handleEdit(schedule)">✏️</view>
					<view class="action-delete" @click="handleDelete(schedule)">🗑️</view>
				</view>
			</view>
		</template>
		<view v-else class="empty-schedule">
			<!-- <image class="empty-icon" src="/static/empty-schedule.png" mode="widthFix"></image> -->
			<text class="empty-text">暂无日程</text>
		</view>
	</view>
</template>

<script setup>
import { ref, watch } from 'vue';

// 接收选中日期属性
const props = defineProps({
	selectedDate: {
		type: Date,
		default: () => new Date()
	}
});

// 发送事件
const emit = defineEmits(['edit', 'delete']);

// 日程列表数据
const scheduleList = ref([]);

// 获取日程列表
const fetchScheduleList = () => {
	// 真实项目中应该从服务器获取数据
	// 这里只是模拟
	console.log('获取日期日程', props.selectedDate);
	
	// 根据选中的日期，展示不同的日程（模拟数据）
	const day = props.selectedDate.getDate();
	
	if (day % 5 === 1) {
		// 有日程的日子
		scheduleList.value = [
			{
				id: 1,
				title: '小程序开发',
				time: '全天',
				tagName: '默认日历',
				tagColor: '#0066FF',
				showActions: true
			},
			{
				id: 2,
				title: '小程序开发',
				time: '11:20～15:00',
				tagName: '默认日历',
				tagColor: '#0066FF',
				showActions: false
			},
			{
				id: 3,
				title: '小程序开发',
				time: '11:20～15:00',
				tagName: '默认日历',
				tagColor: '#0066FF',
				showActions: false
			}
		];
	} else {
		// 无日程的日子
		scheduleList.value = [];
	}
};

// 编辑日程
const handleEdit = (schedule) => {
	emit('edit', schedule);
};

// 删除日程
const handleDelete = (schedule) => {
	emit('delete', schedule);
};

// 监听日期变化
watch(() => props.selectedDate, () => {
	fetchScheduleList();
}, { immediate: true });

// 暴露方法
defineExpose({
	fetchScheduleList
});
</script>

<style lang="scss" scoped>
.schedule-list {
	flex: 1;
	padding: 0 0 calc(50rpx + env(safe-area-inset-bottom));
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	
	.schedule-item {
		display: flex;
		padding: 30rpx 40rpx;
		border-bottom: 1rpx solid #f0f0f0;
		
		.user-avatar {
			width: 80rpx;
			height: 80rpx;
			background-color: #333;
			border-radius: 50%;
			margin-right: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.avatar-text {
				color: #fff;
				font-size: 24rpx;
			}
		}
		
		.schedule-content {
			flex: 1;
			
			.schedule-title {
				font-size: 32rpx;
				margin-bottom: 10rpx;
			}
			
			.schedule-time {
				font-size: 28rpx;
				color: #666;
				margin-bottom: 10rpx;
			}
			
			.schedule-tag {
				display: flex;
				align-items: center;
				
				.tag-dot {
					width: 16rpx;
					height: 16rpx;
					border-radius: 50%;
					margin-right: 10rpx;
				}
				
				.tag-name {
					font-size: 26rpx;
					color: #999;
				}
			}
		}
		
		.schedule-actions {
			display: flex;
			align-items: center;
			
			.action-edit, .action-delete {
				margin-left: 20rpx;
				font-size: 36rpx;
			}
		}
	}
	
	.empty-schedule {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 100rpx 0;
		height: 100%;
		min-height: 300rpx;
		
		.empty-text {
			font-size: 32rpx;
			color: #999;
		}
	}
}
</style> 